class StorageManager {
  static async saveReminder(reminder) {
    const reminders = await this.getReminders();
    reminders.push(reminder);
    await chrome.storage.local.set({ reminders });
  }

  static async getReminders() {
    const data = await chrome.storage.local.get('reminders');
    return data.reminders || [];
  }
  
  static async markAsCompleted(reminderId) {
    const reminders = await this.getReminders();
    const updatedReminders = reminders.map(r => {
      if (r.id === reminderId) {
        return { ...r, completed: true };
      }
      return r;
    });
    await chrome.storage.local.set({ reminders: updatedReminders });
  }

  static async cleanupOldReminders(days) {
    const reminders = await this.getReminders();
    const cutoffDate = new Date();
    cutoffDate.setDate(cutoffDate.getDate() - days);
    
    const filteredReminders = reminders.filter(reminder => {
      if (!reminder.completed) return true;
      const reminderDate = new Date(reminder.completedAt);
      return reminderDate > cutoffDate;
    });
    
    await chrome.storage.local.set({ reminders: filteredReminders });
  }
}

export default StorageManager; 